<?php

class Config implements \ArrayAccess {

    protected $path;
    protected $configs = array();

    public function __construct() {
        $this->path = BASE_PATH . '/Configs';
    }

    public function offsetGet($key) {
        if (empty($this->configs[$key])) {
            $file_path = $this->path . '/' . $key . '.php';
            if (file_exists($file_path)) {
                $config = require $file_path;
                $this->configs[$key] = $config;
            }else{
                exit("file not exists");
            }
        }
        return $this->configs[$key];
    }

    public function offsetSet($key, $value) {
        throw new \Exception("cannot write config file");
    }

    public function offsetExists($key) {
        return isset($this->configs[$key]);
    }

    public function offsetUnset($key) {
        unset($this->configs[$key]);
    }

}
